package com.example.demo;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        try (
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(Files.newOutputStream(Paths.get("D:\\test.txt")));
                ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(Paths.get("D:\\test.txt")))
        ){
            objectOutputStream.writeObject(list);
            Object o = objectInputStream.readObject();
            System.out.println(o);
            Files.delete(Paths.get("D:\\test.txt"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
